let mindata = (function () {
    let swiperWrapper = document.querySelector('.swiper-wrapper');
    let data = null;
    let section = document.querySelector('.container2');
    let wrapper = section.querySelector('.wrapper');
    let slideList = Array.from(wrapper.querySelectorAll('.slide'));
    // let slide = wrapper.querySelector('.slide');


    function getData() {
        // 获取数据
        return new Promise((resolve, reject) => {
            let xhr = new XMLHttpRequest;
            xhr.open('get', './js/data.json');
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && this.status === 200) {
                    data = JSON.parse(xhr.response);
                    resolve(data);
                }
            }
            xhr.send();
        })
    }
    // 渲染页面
    const render = function render(newdata) {
        let str = "";
        for (let i = 0; i < 10; i++) {
            let { title, details, pic } = newdata[i];
            str += `<div class="swiper-slide">
                <img src="${pic}" alt="">
                <div class="swipertx">
                  <h2>${title}</h2>
                  <p>${details}</p>
                </div>
              </div>`;
        }
        swiperWrapper.innerHTML = str;

        var swiper = new Swiper(".mySwiper", {
            slidesPerView: 4,
            spaceBetween: 10,
            slidesPerGroup: 2,
            loop: true,
            loopFillGroupWithBlank: true,
            navigation: {
                nextEl: ".swiper-button-next",
                prevEl: ".swiper-button-prev",
            },
        });
    };

    (async () => {
        let value = await getData();
        render(value);
        // handle(value);

    })()
})()
